<style type="text/css">
    .demo-upload-list {
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
        margin-right: 4px;
    }

    .demo-upload-list img {
        width: 100%;
        height: 100%;
    }

    .demo-upload-list-cover {
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .6);
    }

    .demo-upload-list:hover .demo-upload-list-cover {
        display: block;
    }

    .demo-upload-list-cover i {
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }

    .selected-search {
        border: 1px solid #dddee1;
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="绑定车辆" prop="carId">
            <i-select v-model="formValidate.carId" placeholder="请选择绑定车辆">
                <template v-for="(item,index) in carArr">
                    <i-option :value="item.Id">{{item.Platenum}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item label="起始时间">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" placeholder="选择有效日期（起始时间）" @on-change="changeUpDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="结束时间">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" placeholder="选择有效日期（结束时间）" @on-change="changeGetDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="是否为本车固定驾驶员" prop="issolid">
            <i-select v-model="formValidate.issolid" placeholder="请选择是否为本车固定驾驶员">
                <i-option value="true">是</i-option>
                <i-option value="false">否</i-option>
            </i-select>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>

    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import upImage from '../../components/upImage';
    import baseUtil from '../../assets/utils/base-util';


    /**
     * 人员Id peopleid, 驾驶证正本照片路径 licenseimage,
     * 驾驶证副本照片路径 licenseimageb,
     * 上一次驾驶审查日期 lastcheckdate,
     * 获取驾驶证时间 firstcheckdate
     * 下一次驾照审查时间 nextcheckdate，
     * 驾驶证编号 licenseid，准驾车型 alloweddrive
     */

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    startdate: '',
                    enddate: '',
                    issolid:'',
                },
                ruleValidate: {},
                driverId: '',
                carArr: [],
            }
        },
        components: {
            upImage
        },
        mounted: function () {
            // this.uploadList();
            this.driverId = this.$route.query.id;
            this.getCarData();

        },

        methods: {
            changeUpDate: function (date) {
                this.formValidate.startdate = date;
            },
            changeGetDate: function (date) {
                this.formValidate.enddate = date;
            },
            //获取车辆列表
            getCarData() {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.CarList, para, function (res) {
                    that.$Loading.finish();
                    // that.total = res.Msg.TotalCount;
                    // that.current = res.Msg.CurrentPage;
                    that.carArr = res.Msg;
                });

            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },

            //添加
            addData: function (model) {
                let that = this;


                model.driverid = this.driverId;
                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.SetDriverToCar, params, function (res) {
                    that.$Loading.finish();

                    that.$Modal.confirm({
                        title: '操作成功',
                        content: '请选择下一步操作',
                        okText: '继续添加',
                        cancelText: '返回列表',
                        onOk: () => {
                            that.$router.go(0);
                        },
                        onCancel: () => {
                            baseUtil.pageJump(that, that.driverId, 'BindCarList')
                        }
                    });

                });
            },

        }
    }
</script>
